#include "scene_main.h"
#include "object_world.h"
#include "object_screen.h"
#include "actor.h"
#include "player.h"
#include "enemy.h"
#include "spawner.h"
#include "core/scene.h"
#include "raw/timer.h"
#include "world/effect.h"
#include "screen/ui_mouse.h"
#include "raw/weapon.h"
#include "weapon_thunder.h"
#include "world/spell.h"

void SceneMain::init()
{
    Scene::init();
    SDL_HideCursor();
    world_size_ = game.getScreenSize() * 3.0f;
    // camera_position_ = glm::vec2(-100.0f);
    camera_position_ = world_size_ / 2.0f - game.getScreenSize() / 2.0f;
    auto player_ = new Player();
    player_->init();
    player_->setPosition(world_size_/2.0f);
    addChild(player_);

    // auto enemy = new Enemy();
    // enemy->init();
    // enemy->setTarget(player_);
    // enemy->setMaxSpeed(200.0f);
    // enemy->setPosition(world_size_/2.0f + glm::vec2(200.0f));
    // addChild(enemy);

    end_timer_ = Timer::addTimerChild(this);

    spawner_ = new Spawner();
    spawner_->init();
    spawner_->setTarget(player_);
    addChild(spawner_);

    ui_mouse_ = UIMouse::addUIMouseChild(this, "assets/UI/29.png", "assets/UI/30.png", 2.0f, Anchor::CENTER);

}

bool SceneMain::handleEvents(SDL_Event &event)
{
    if (Scene::handleEvents(event)) return true;
    return false;
}

void SceneMain::update(float dt)
{
    Scene::update(dt);
}

void SceneMain::render()
{
    renderBackground();
    Scene::render();
}

void SceneMain::clean()
{
    Scene::clean();
}

void SceneMain::renderBackground()
{
    auto start = -camera_position_;
    auto end = world_size_ - camera_position_;
    game.drawGrid(start, end, 80.0f, {0.1, 0.1, 0.1, 1.0});
    game.drawBoundary(start, end, 20.0f, {0.0, 1.0, 1.0, 1.0});
}
